#include"lars_api.h"
#include<vector>
#include<string>


// 开发者业务模块
int main(int argc, char* argv[]){
    if(argc != 3){
        printf("usage: ./get_route [modid] [cmdid]\n");
        return 1;
    }

    int modid = atoi(argv[1]);
    int cmdid = atoi(argv[2]);

    lars_client client;

    route_set route;

    // 1.将modid和cmdid进行注册
    int ret = client.reg_init(modid, cmdid);
    if(ret == 0){
        ret = client.get_route(modid, cmdid, route);
        if(ret == 0){
            printf("modid:%d, cmdid:%d\n", modid, cmdid);
            // 获得当前要求的modid和cmdid下的所有host的IP和port
            for(route_set_it it=route.begin(); it!=route.end(); it++){
                printf("===>host ip:%s, port:%d\n", it->first.c_str(), it->second);
            }
        }
    }
    else if(ret == 2){
        fprintf(stderr, "system error:%d\n",ret);
    }
    else if(ret == 3){
        fprintf(stderr, "data is not exist:%d\n",ret);
    }


    return 0;
}
